<template>
	
		<view class="content">
			<image class="image_icon"></image>
			<view class="cu-load" :class="!isLoad?'loading':'over'">loading...</view>
		</view>
	
</template>

<script>
	var _self = null
	export default {
		
		data() {
			return {
				isLoad: false
			}
		},
		// onLoad(){
		mounted(){
			_self = this
			console.log('splash onLoad'+_self.$constant.BASEURL);
			if (getApp().globalData.debug) {
				uni.setStorage({
					key: 'openid',
					data: {openid:'oFRk5vzPRq3jPeiGeJOm-JEGW7g4',nickname:'小明',headimgurl:'https://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/46'},
				success: function() {
					console.log('successsp');
					getApp().globalData.openid='oFRk5vzPRq3jPeiGeJOm-JEGW7g4';
				}
				});
			}
			//判断本地是否已缓存openid
			
			uni.getStorage({
				key: 'openid',
				success: function(res) {
					 //console.log("ss",res);
					//alert(JSON.stringify(res.data))
					getApp().globalData.openid=res.data.openid;
				},
				fail: function(res) {
					 console.log('fill = ', res);
					_self.getOpenId();
				}
			});
			
			console.log("跳转indexnew页面")
			uni.switchTab({
				url: '../index/indexnew'
			});
			
		},
		methods: {
			getOpenId() {
				//请求获取openId
				uni.request({
					url: _self.$constant.BASEURL + _self.$constant.GET_OPENID,
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						code: getApp().globalData.sceneId
					},
					success: (res) => {
						console.log("获取openid:",res)
						//跳转到登陆页面
						if (res.data.code == 0) {
							console.log('openid', res.data.data.openid)
							//保存openid
							uni.setStorage({
								key: 'openid',
								data: res.data.data,
								success: function() {
									// console.log('success111');
									//alert(res.data.data.openid)
									getApp().globalData.openid=res.data.data.openid;
								}
							});
							
						} else {
							uni.showModal({
								title: "提示",
								content: "您需要在同意授权微信登录之后，才能继续使用",
								showCancel: false,
								success() {
									//关闭当前网页  顺序不能颠倒 同时兼容ios和android
									document.addEventListener('WeixinJSBridgeReady', function() {
										WeixinJSBridge.call('closeWindow');
									}, false);
									WeixinJSBridge.call('closeWindow');
								}
							})
						}
					}
				});
			}
		}
	}
</script>

<style>
	.image_icon {
		width: 200upx;
		height: 200upx;
		margin-top: 400upx;
	}
	
	.cu-load.loading::after {
		content: "";
	}

</style>
